import BaseStore from "@/base/BaseStore";
import {Message} from "@biz/Components";

export default class Store extends BaseStore{
    constructor(props,config, action) {
        super(props, config, action)
        this.state = this.getInitialState()
    }

    getInitialSo() {
        return {
        }
    }

    onSync(){
        this.setState({loading:true})
    }
    onSyncCompleted(res){
        this.setState({loading:false})
        super.dealResponse(res,()=>{
            let {total, created, updated} = res.vo;
            Message.success(`同步总数：${total}, 创建:${created}, 更新：${updated}`)
            super.refreshList();
        })
    }
    onSyncByGeekId(){
        this.setState({loading:true})
    }
    onSyncByGeekIdCompleted(res){
        this.setState({loading:false})
        super.dealCommonResponse(res,()=>{
            super.refreshList();
        })
    }
    onTestMqtt(){
        this.setState({loading:true})
    }
    onTestMqttCompleted(res){
        this.setState({loading:false})
        super.dealResponse(res,()=>{
            Message.success(res.vo);
        })
    }

    onReset(){
        this.setState({loading:true})
    }
    onResetCompleted(res){
        this.setState({loading:false})
        super.dealResponse(res,()=>{
            Message.success(res.vo);
        })
    }

    onGetShopDeviceList(){
        this.setState({detailLoading:true})
    }
    onGetShopDeviceListCompleted(callback, res){
        this.setState({detailLoading:false});
        super.dealResponse(res,()=>{
            callback && callback(res.voList);
            this.setState({deviceList:res.voList||[]})
        })
    }

    onPreBind(detail){
        this.setState({detail, modalStatus:"bind"});
    }
    onBind(){
        this.setState({detailLoading:true})
    }
    onBindCompleted(callback, res){
        this.setState({detailLoading:false});
        super.dealCommonResponse(res,()=>{
            callback && callback();
            Message.success(res.vo);
            super.refreshList();
        })
    }
}